function FirstAssistant() {
	this.servers = {
		urls: [
			'http://192.168.1.37/xmpp-httpbind',
			'http://blindeshendl.cg.tuwien.ac.at/xmpp-httpbind'
		],
		attributes: {
			choices: [
				{label: "psi", value: 0},
				{label: "hendl", value: 1}
			]
		},
		model: {
			value: 0,
			disabled: false
		}
	};
	this.username = {
		attributes: {
			hintText: 'Username'
		},
		model: {
			value: "asdf"
		}
	};
	this.password = {
		attributes: {
			hintText: 'Password'
		},
		model: {
			value: "asdf"
		}
	};

	this.register = {
		attributes: {
			type: Mojo.Widget.ActivityButton,
			label: "Register"
		},
		model: {}
	};
	this.login = {
		attributes: {
			type: Mojo.Widget.ActivityButton,
			label: "Login"
		},
		model: {}
	};

	this.appAssistant = Mojo.Controller.getAppController().assistant;
}


FirstAssistant.prototype.onRegister = function() {
	var idx = this.servers.model.value;
	var url = this.servers.urls[idx];
};

FirstAssistant.prototype.getFormValues = function() {
	var idx = this.servers.model.value;
	var url = this.servers.urls[idx];
	var domain = this.servers.attributes.choices[idx].label;
	var jid = this.username.model.value + "@" + domain + "/mobile";
	var pw = this.password.model.value;

	return {
		url: url,
		jid: jid,
		pw: pw
	};
};


FirstAssistant.prototype.onLogin = function() {
	this.appAssistant.setCookie(this.getFormValues());
	this.appAssistant.handleLaunch({source: 'login'});
};


FirstAssistant.prototype.setup = function() {
	var c = this.controller, e = Mojo.Event;
	this.$ = jQuery(this.controller.document);
	c.setupWidget('servers', this.servers.attributes, this.servers.model);
	c.setupWidget('username', this.username.attributes, this.username.model);
	c.setupWidget('password', this.password.attributes, this.password.model);
	c.setupWidget('register',  this.register.attributes, this.register.model);
	c.setupWidget('login',  this.login.attributes, this.login.model);
//	e.listen(c.get('register'), e.tap, this.onRegister.bind(this));
	e.listen(c.get('login'), e.tap, this.onLogin.bind(this));
};

FirstAssistant.prototype.activate = function(event) {
};

FirstAssistant.prototype.deactivate = function(event) {
};

